<?php

class SecurityHelper {

	public static function validateRequest($request)
	{

	}
	
    /**
     * @param $request
     *
     * @return string
     */
    public static function generateDataFromOutgoingRequest($request)
    {
        $data = [
            'method'       => $request->method(),
            'client_ip'    => $request->ip(),
            'path'         => $request->path(),
            'query_string' => self::orderQueryString($request->query()),
            'host'		   => $request->getHttpHost()
        ];
        return implode($data, '');
    }

    /**
     * @param $queryString
     *
     * @return string
     */
    protected static function orderQueryString($query)
    {
        $query = self::kmultisort($query);
        return http_build_query($query);
    }

    /**
     * @description Sort multidimensional array by key
     * @param array $array
     *
     * @return array
     */
    protected static function kmultisort(array &$array)
    {
        ksort($array);

        foreach ($array as &$value) {
            if (is_array($value)) {
                self::kmultisort($value);
            }
        }

        return $array;
    }
}